package com.soujiayi.adapter;

import java.util.List;

import com.soujiayi.activity.R;
import com.soujiayi.activity.R.id;
import com.soujiayi.activity.R.layout;
import com.soujiayi.model.Category;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ProductClassifyGridViewAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<Integer> imageData;
	private List<Category> textData;

	public ProductClassifyGridViewAdapter(Context context,List<Integer> imageData, List<Category> textData) {
		this.textData = textData;
		this.imageData = imageData;
		this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return textData.size();
	}

	@Override
	public Object getItem(int position) {
		return textData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		View view = convertView;
		ViewHolder holder; 
		if(view == null){
			view = mInflater.inflate(R.layout.product_classify_grideview_item, null);
			holder = new ViewHolder();
			holder.image = (ImageView)view.findViewById(R.id.product_classify_item_img);
			holder.text = (TextView)view.findViewById(R.id.product_classify_item_text);
			view.setTag(holder);
		}else{
			holder = (ViewHolder)view.getTag(); 
		}
		bindView(holder, position);
		view.setSelected(true);

		return view;
	}
	
	private void bindView(ViewHolder holder, int position){
		//holder.image.setImageResource(imageData.get(position));
		holder.text.setText(textData.get(position).getName());
	}
	
	class ViewHolder{
		ImageView image;
		TextView text;
	}


}
